from rest_framework import serializers
from app import models


class serviceSerializer(serializers.ModelSerializer):
    ip = serializers.IPAddressField()
    hostname = serializers.CharField()

    class Meta:
        model = models.Service
        fields = '__all__'


class UserSerializer(serializers.HyperlinkedModelSerializer):
    username = serializers.CharField()

    class Meta:
        model = models.User
        fields = ('username', 'id')


class KeySerializer(serializers.ModelSerializer):
    name = serializers.CharField()
    username = serializers.CharField()
    keyPath = serializers.CharField()
    password = serializers.CharField()
    ChangeUser = serializers.ReadOnlyField(default=None, required=False, source='ChangeUser.username', read_only=True, allow_null=True)
    # createUser = UserSerializer(read_only=True)
    createUser = UserSerializer(required=False, read_only=True, allow_null=True)
    # createUser = serializers.PrimaryKeyRelatedField(queryset=models.User.objects.all())

    class Meta:
        model = models.Key
        fields = '__all__'
